package com.user.gamecenter.network.conversion;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * Created by cms on 2016/12/7.
 */

final class GsonResponseBodyConverter<T> implements Converter<ResponseBody, String> {
    private final Gson gson;
    private final TypeAdapter<T> adapter;

    GsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
        this.gson = gson;
        this.adapter = adapter;
    }

    /*  @Override
      public T convert(ResponseBody value) throws IOException {

          JsonReader jsonReader = gson.newJsonReader(value.charStream());
          try {
              return adapter.read(jsonReader);
          } finally {
              value.close();
          }
      }*/
    @Override
    public String convert(ResponseBody value) throws IOException {

        String string = value.string();
        try {
            return string;
        } finally {
            value.close();
        }
    }

}
